import java.util.Arrays;

class MyRunnable implements Runnable {
    @Override
    public void run() {

    }
}



public class Test2 {
    public static void main(String[] args) {
        int[] arr = {3} ;
        System.out.println(rob(arr));
    }
    public static int rob(int[] nums) {
        if(nums == null || nums.length == 0) return 0 ;
        int len = nums.length ;
        return Math.max(massage(nums, 2 , len-1)+nums[0] , massage(nums,1 ,len)) ;
    }
    public static int massage(int[] nums , int left , int right) {
        if(nums == null || right-left <= 0) return 0  ;
        int len = right - left ;
        int[] fdp = new int[len] ;
        int[] gdp = new int[len] ;
        fdp[0] = nums[left] ;

        for(int i=1 ; i < len ; i ++){
            fdp[i] = nums[left+i] + gdp[i-1] ;
            gdp[i] = Math.max(gdp[i-1] , fdp[i-1]) ;
        }
        return Math.max(fdp[len-1] , gdp[len-1]) ;
    }

}
